/*
 * MIT License
 *
 * Copyright (c) 2024-2048 冰羽
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

package cn.star.framework.rbac.service;

import cn.star.framework.core.IService;
import cn.star.framework.rbac.core.IRbacUser;

/**
 * Rbac 用户 服务<br>
 *
 * @author zhaoweiping
 *     <p style='color: red'>Created on 2024-09-23 11:06:00
 * @since 3.0.0
 */
public interface IRbacUserService<T extends IRbacUser<?>> extends IService<T, String> {

  /**
   * 使用账号获取用户
   *
   * @param username 账号
   * @return 用户
   */
  T findByUsername(String username);

  /**
   * 锁定用户
   *
   * @param user 用户
   */
  void lock(T user);

  /**
   * 锁定用户
   *
   * @param id 用户Id
   */
  default void lock(String id) {
    this.lock(this.findById(id));
  }

  /**
   * 解锁用户
   *
   * @param user 用户
   */
  void unlock(T user);

  /**
   * 解锁用户
   *
   * @param id 用户Id
   */
  default void unlock(String id) {
    this.unlock(this.findById(id));
  }

  /**
   * 启用用户
   *
   * @param user 用户
   */
  void enable(T user);

  /**
   * 启用用户
   *
   * @param id 用户Id
   */
  default void enable(String id) {
    this.enable(this.findById(id));
  }

  /**
   * 禁用用户
   *
   * @param user 用户
   */
  void disable(T user);

  /**
   * 禁用用户
   *
   * @param id 用户Id
   */
  default void disable(String id) {
    this.disable(this.findById(id));
  }

  /**
   * 密码重置
   *
   * @param id 用户Id
   * @param password 新密码
   */
  void passwordRest(String id, String password);

  /**
   * 密码修改
   *
   * @param id 用户Id
   * @param newPassword 新密码
   * @param oldPassword 旧密码
   */
  void passwordModify(String id, String newPassword, String oldPassword);
}
